import datetime
import logging
log = logging.getLogger("dbloader")

from google.appengine.ext import db
import statsdb

class RecordLoader(Loader):
  def __init__(self):
    Loader.__init__(self, 'Record',
                    [('date', lambda x: datetime.datetime.strptime(x, "%Y-%m-%d")),
                     ('dfmt', str),
                     ('value', float),
                     ('unit', lambda x: x.decode("utf-8")),
                     ('tags', lambda x: x.decode("utf-8").split(" ")),
                     ('source', str)
                     ])

  def GenerateKey(self, i, values):
    return statsdb.GenRecordKeyName(
        datetime.datetime.strptime(values[0], "%Y-%m-%d"),
        values[4].decode("utf-8").split(" ")) 
